﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Script.Serialization;

namespace Chart.Net
{
    public class RaphaelBarChart : BarChart
    {
        public override string GetScripts()
        {
            return "<script src=\"../scripts/raphael/g.raphael-min.js\"></script>" +
                "<script src=\"../scripts/raphael/g.bar.js\"></script>" +
                "<script src=\"../scripts/raphael/bar.js\"></script>";
        }

        public override string GetBody()
        {
            StringBuilder result = new StringBuilder();

            string chartId = string.IsNullOrEmpty(Title) ? "untitled" : Title.Replace(' ', '-');
            string json = new JavaScriptSerializer().Serialize(barCollection);
            string template = Utility.ReadTemplate(Constants.TemplateRaphaelBar);
            result.AppendFormat(template, Title, json, chartId);
            return result.ToString();
        }
    }
}
